const addRouteRecode = (route,pathList,pathMap,parentRecode)=>{
    let path = parentRecode ? `${parentRecode.path}/${route.path}`:route.path;
    let recode = { //根据当前路由产生一个记录  path/component
        path:path,
        component:route.component, //...
        parent:parentRecode //记录中保存一下父路径是谁
    }
    if(!pathMap[path]){ //防止用户别写路由时有重复的，不去覆盖
        pathMap[path] = recode;
        pathList.push(path);
    }
    //要将子路由也放到对应的pathMap和pathList
    if(route.children){
        route.children.forEach(r=>{
            addRouteRecode(r,pathList,pathMap,recode);
        })
    }
    
}

//具备新增和添加的功能
function createRouteMap(routes,oldPathList,oldPathMap){
    let pathList = oldPathList || [];
    let pathMap = oldPathMap || {};
    routes.forEach(route=>{
        addRouteRecode(route,pathList,pathMap);
    })

    return{
        pathList,
        pathMap
    }
}

export default createRouteMap;

